import time

# 生成单号（这里简单生成，实际可根据规则生成）
order_number = "DH" + time.strftime("%Y%m%d%H%M%S")

# 获取当前时间
current_time = time.strftime("%Y-%m-%d %H:%M:%S")

# 商品信息列表，存储（名称，数量，单价，金额）
products = []
# 商品名称列表，可根据实际情况修改
product_names = ["金士顿U盘8G", "胜创16GTF卡", "读卡器", "网线2米"]

# 循环接收每个商品的价格
for name in product_names:
    while True:
        try:
            price = float(input(f"请输入{name}的价格："))
            break
        except ValueError:
            print("请输入有效的数字！")
    # 假设每个商品数量都是1
    quantity = 1
    amount = quantity * price
    products.append((name, quantity, price, amount))

# 计算总数、总额
total_count = len(products)
total_amount = sum(amount for _, _, _, amount in products)
discounted_amount = total_amount  # 假设无折扣
paid = total_amount
change = paid - discounted_amount
cashier = "管理员"

# 打印购物小票
print("." * 40)
print(f"单号：{order_number}")
print(f"时间：{current_time}")
print("." * 40)
print(f"{'名称':<15}{'数量':<8}{'单价':<8}{'金额':<8}")
for name, quantity, price, amount in products:
    print(f"{name:<15}{quantity:<8}{price:<8.2f}{amount:<8.2f}")
print("." * 40)
print(f"总数：{total_count}          总额：{total_amount:.2f}")
print(f"折后总额：{discounted_amount:.2f}")
print(f"实收：{paid:.2f}        找零：{change:.2f}")
print(f"收银：{cashier}")
print("." * 40)